package com.dudy.singleton;

/**
 * @program: zhuguangDemo
 * @description: ${description}
 * @author: dudy
 * @create: 2018-04-05 20:34
 **/
public class Singleton2 {
    private static Singleton2 instance;
    private Singleton2() {

    }
    public static Singleton2 getInstance() {
        if (instance == null) {
            synchronized (instance) {
                if (instance == null) {
                    //由于jvm的指令重排序，导致有几率instance被赋值为一个空对象，那么下一个线程就会再次初始化
                    instance = new Singleton2();
                }
            }
        }
        return instance;
    }
}
